package edu.tongji.jiaowu.webapp.action.handler;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.tongji.quickCRUDQ.model.CommonBean;
import com.tongji.quickCRUDQ.util.JsonDataSet;
import com.tongji.quickCRUDQ.webapp.handler.QuickHandler;

import edu.tongji.jiaowu.service.VcodeManager;
import edu.tongji.jiaowu.webapp.session.SessionParameter;
import edu.tongji.jiaowu.webapp.session.SessionParameterLocal;

public class EvaluationIndexHandler extends HandlerInterceptorAdapter implements QuickHandler {
	private VcodeManager vcodeManager;
	
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object object, ModelAndView mv) throws Exception {
		CommonBean schoolYears=vcodeManager.findCodes("SCHOOL_YEAR");
		String yearJson=JsonDataSet.commonbeanToJsonArray(schoolYears, "code", "name");
		CommonBean schoolSemesters=vcodeManager.findCodes("SCHOOL_SEMESTER");
		String semeterJson=JsonDataSet.commonbeanToJsonArray(schoolSemesters, "code", "name");
		CommonBean courseTypes=vcodeManager.findCodes("EV_COURSE_TYPE");
		String courseTypeJson=JsonDataSet.commonbeanToJsonArray(courseTypes, "code", "name");
		Map model=(Map) mv.getModelMap().get("model");
		model.put("yearJson", yearJson);
		model.put("semesterJson", semeterJson);
		model.put("courseTypeJson", courseTypeJson);
		
		SessionParameter parameter=SessionParameterLocal.getSessionParameter();
		String currentYear=parameter.getCurrentSchoolYear();
		String currentSemester=parameter.getCurrentSchoolSemester();
		model.put("currentYear", currentYear);
		model.put("currentSemester", currentSemester);
		super.postHandle(request, response, object, mv);
	}	

	public VcodeManager getVcodeManager() {
		return vcodeManager;
	}

	public void setVcodeManager(VcodeManager vcodeManager) {
		this.vcodeManager = vcodeManager;
	}

}
